package com.midea.ai.air.ui.more.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseFragment;

/**
 * Created by ouyangdi on 2016/4/12.
 * 个人资料->性别设置Fragment
 */
public class MorePersonSexFragment extends BaseFragment implements View.OnClickListener{
    public static final int SEX_UNSPECIFIC = 0;
    public static final int SEX_MALE = 1;
    public static final int SEX_FEMALE = 2;

    private RelativeLayout mLayoutMale, mLayoutFemale;
    private ImageView mStatusMale, mStatusfemale;
    private int mSex = SEX_UNSPECIFIC;    //性别,0表示未设置,1表示为男, 2表示为女

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_more_person_sex, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        mLayoutMale = (RelativeLayout)view.findViewById(R.id.layout_select_male);
        mLayoutMale.setOnClickListener(this);
        mLayoutFemale = (RelativeLayout)view.findViewById(R.id.layout_select_female);
        mLayoutFemale.setOnClickListener(this);
        mStatusMale = (ImageView)view.findViewById(R.id.iv_male_selected);
        mStatusfemale = (ImageView)view.findViewById(R.id.iv_female_selected);

        switch (mSex) {
            case SEX_UNSPECIFIC:
                mStatusMale.setVisibility(View.GONE);
                mStatusfemale.setVisibility(View.GONE);
                break;
            case SEX_MALE:
                mStatusMale.setVisibility(View.VISIBLE);
                mStatusfemale.setVisibility(View.GONE);
                break;
            case SEX_FEMALE:
                mStatusMale.setVisibility(View.GONE);
                mStatusfemale.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_select_male:
                if(mSex != SEX_MALE) {
                    mStatusMale.setVisibility(View.VISIBLE);
                    mStatusfemale.setVisibility(View.GONE);
                }
                mSex = SEX_MALE;
                break;
            case R.id.layout_select_female:
                if(mSex != SEX_FEMALE) {
                    mStatusMale.setVisibility(View.GONE);
                    mStatusfemale.setVisibility(View.VISIBLE);
                }
                mSex = SEX_FEMALE;
                break;
        }
    }
}
